import 'package:flutter/cupertino.dart';
import 'package:quick_code_platform/constant/constant.dart';
import 'package:quick_code_platform/custom/custom_dialog/get_widget_dialog_view.dart';
import 'package:quick_code_platform/util/permission_utils.dart';
import 'package:get/get.dart';
import '../../routes/routes.dart';
import '../base/base_controller.dart';
import 'package:permission_handler/permission_handler.dart';

class GuideController extends BaseController {

  @override
  void onReady() {
    super.onReady();
    checkLoginPermission();
  }

  void checkLoginPermission() {
    List<Permission> permissions = [
      Permission.storage,
    ];
    PermissionUtils.check(permissions,
        onSuccess: () async {
          if (GetPlatform.isAndroid) {
            clearNetLogs();
          }
          if (quickCatalogueBaseUrl.isEmpty) {
            Get.dialog(
                WillPopScope(
                  onWillPop: () async => false,
                  child: GetWidgetDialogWidget(
                    title: "提示",
                    message: "请先配置文件地址和接口请求地址",
                    confirmText: "去配置",
                    onConfirmEvent: () {
                      Get.back();
                      Get.offAndToNamed(Routes.setting, arguments: {'isSetting' : false},);
                    },
                  ),
                ),
                barrierDismissible: false);
          } else {
            saveUpdateApp(isGuide: true);
          }
        },
        onFailed: () {},
        onOpenSetting: () {
          openAppSettings();
        });
  }
}
